//
//  UIButton+oddBtn.m
//  ZeegingLottery
//
//  Created by 蒂埃里 on 2018/4/14.
//  Copyright © 2018年 蒂埃里. All rights reserved.
//

#import "UIButton+oddBtn.h"

@implementation UIButton (oddBtn)

- (void)buttonWithType:(buttonTyppe )type textString:(NSString *)textStr subString:(NSString *)subStr
{
    
    [self.layer setBorderWidth:kBorderWidth];
    [self.layer setBorderColor:BorderColor.CGColor];
    
    [self setTitle:textStr forState:UIControlStateNormal];
    [self setTitleColor:RGBACOLOR(59, 59, 59, 1.0) forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont fontWithName:@"Arial" size:13];
    self.titleLabel.textAlignment = 1;
    self.titleLabel.numberOfLines = 0;
    
    //行间距离
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.alignment = NSTextAlignmentCenter;
    paragraphStyle.lineSpacing = 6.0;
    NSDictionary *ats = @{
                          NSParagraphStyleAttributeName : paragraphStyle,
                          };
//    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]init];
//    switch (type) {
//        case oddsButtonTextLabelVertical:{
//
//            str = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@\n%@",textStr,subStr] attributes:ats];
//        }
//            break;
//
//        case oddsButtonTextLabelHorizontall:{
//
//            str = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ %@",textStr,subStr] attributes:nil];
//
//        }
//            break;
//    }
//
//    //文字分行 并设置字体颜色，大小
//
//    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:btnFontSize] range:NSMakeRange(0, textStr.length)];
//    [str addAttribute:NSForegroundColorAttributeName value:mainTextColor range:NSMakeRange(0, textStr.length)];
//    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:btnFontSize] range:NSMakeRange(str.length - subStr.length, subStr.length)];
//    [str addAttribute:NSForegroundColorAttributeName value:detailTextColor range:NSMakeRange(str.length - subStr.length, subStr.length)];
//    [self setAttributedTitle:str forState:UIControlStateNormal];

    NSMutableAttributedString *normalStr = [[NSMutableAttributedString alloc]init];
    NSMutableAttributedString *selectedStr = [[NSMutableAttributedString alloc]init];
    switch (type) {
        case oddsButtonTextLabelVertical:{
            
            normalStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@\n%@",textStr,subStr] attributes:ats];
            selectedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@\n%@",textStr,subStr] attributes:ats];
        }
            break;
            
        case oddsButtonTextLabelHorizontall:{
            
            normalStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ %@",textStr,subStr] attributes:nil];
            selectedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ %@",textStr,subStr] attributes:nil];
            
        }
            break;
    }
    
    //文字分行 并设置字体颜色，大小
    [normalStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:btnFontSize] range:NSMakeRange(0, textStr.length)];
    [normalStr addAttribute:NSForegroundColorAttributeName value:mainTextColor range:NSMakeRange(0, textStr.length)];
    [normalStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:btnFontSize] range:NSMakeRange(normalStr.length - subStr.length, subStr.length)];
    [normalStr addAttribute:NSForegroundColorAttributeName value:detailTextColor range:NSMakeRange(normalStr.length - subStr.length, subStr.length)];
    
    [selectedStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:btnFontSize] range:NSMakeRange(0, textStr.length)];
    [selectedStr addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, textStr.length)];
    [selectedStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:btnFontSize] range:NSMakeRange(selectedStr.length - subStr.length, subStr.length)];
    [selectedStr addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(selectedStr.length - subStr.length, subStr.length)];
    
    [self setAttributedTitle:normalStr forState:UIControlStateNormal];
    [self setAttributedTitle:selectedStr forState:UIControlStateSelected];
    
    
}


@end
